function varargout = CrackGui(varargin)
% CRACKGUI MATLAB code for CrackGui.fig
%      CRACKGUI, by itself, creates a new CRACKGUI or raises the existing
%      singleton*.
%
%      H = CRACKGUI returns the handle to a new CRACKGUI or the handle to
%      the existing singleton*.
%
%      CRACKGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CRACKGUI.M with the given input arguments.
%
%      CRACKGUI('Property','Value',...) creates a new CRACKGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before CrackGui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to CrackGui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help CrackGui

% Last Modified by GUIDE v2.5 20-Aug-2011 13:23:47

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @CrackGui_OpeningFcn, ...
    'gui_OutputFcn',  @CrackGui_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before CrackGui is made visible.
function CrackGui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to CrackGui (see VARARGIN)
global Crack TipEn
% Choose default command line output for CrackGui
handles.output = hObject;
handles.fig_xfem=varargin{2};
handles.haxes=varargin{4};

if ~isempty(Crack)
    set(handles.tbl_crack,'data',Crack(:,2:3),'rowname',Crack(:,1));
elseif ~isempty(TipEn)
    set(handles.edt_tipr,'string',TipEn);
end
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes CrackGui wait for user response (see UIRESUME)
% uiwait(handles.fig_crack);


% --- Outputs from this function are returned to the command line.
function varargout = CrackGui_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edt_tipr_Callback(hObject, eventdata, handles)
% hObject    handle to edt_tipr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edt_tipr as text
%        str2double(get(hObject,'String')) returns contents of edt_tipr as a double


% --- Executes during object creation, after setting all properties.
function edt_tipr_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edt_tipr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edt_crackd_Callback(hObject, eventdata, handles)
% hObject    handle to edt_crackd (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edt_crackd as text
%        str2double(get(hObject,'String')) returns contents of edt_crackd as a double


% --- Executes during object creation, after setting all properties.
function edt_crackd_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edt_crackd (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pbtn_click.
function pbtn_click_Callback(hObject, eventdata, handles)
% hObject    handle to pbtn_click (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Crack
axes(handles.haxes);
[x,y]=ginput;
num=(1:length(x))';
Crack=[num,x,y];
set(handles.tbl_crack,'data',[x,y],'rowname',num)
r=str2double(get(handles.edt_tipr,'string'));
PlotCrack(x,y,r,handles.haxes);

% --- Executes on button press in pbtn_refresh.
function pbtn_refresh_Callback(hObject, eventdata, handles)
% hObject    handle to pbtn_refresh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Crack

data=get(handles.tbl_crack,'data');
if iscell(data)
    data=cell2mat(data);
end
if ~isempty(data)
    x=data(:,1);
    y=data(:,2);
    Crack(:,2:3)=[x,y];
    r=str2double(get(handles.edt_tipr,'string'));
    PlotCrack(x,y,r,handles.haxes);
end
% --- Executes on button press in pbtn_delete.
function pbtn_delete_Callback(hObject, eventdata, handles)
% hObject    handle to pbtn_delete (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ClearFigure('crack');

% --- Executes on button press in pbtn_close.
function pbtn_close_Callback(hObject, eventdata, handles)
% hObject    handle to pbtn_close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
SetFigSize('>>',handles.fig_xfem);
delete(handles.fig_crack)
